<?php

namespace App\Http\Controllers\Backstage;

use App\Http\Controllers\Backstage\BCommonController;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Input;
use App\Models\BackstageModel;
use App\Models\CommonModel;
use App\Models\UserModel;
use Storage;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Libary\Captcha\Code;

// require_once '../app/libary/captcha/Code.class.php';

class CommonController extends BCommonController
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    // protected $redirectTo = '/backstage/common/index';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    // public function __construct()
    // {
    //     $this->middleware('guest', ['except' => 'logout']);
    // }

    // public function index(){
    //     if(isset($_GET['type_id']) && intval($_GET['type_id'])!=0){
    //         $type_id = intval($_GET['type_id']);
    //         if(isset($_GET['keywords'])){
    //             $keywords = trim($_GET['keywords']);
    //             $list = DB::table('article')->where('title','like','%'.$keywords.'%')->where('type_id',$type_id)->orderBy('sort_order','desc')->paginate(15);
    //         }else{
    //             $list = DB::table('article')->where('type_id',$type_id)->orderBy('sort_order','desc')->paginate(15);
    //         }
    //     }else{
    //         if(isset($_GET['keywords'])){
    //             $keywords = trim($_GET['keywords']);
    //             $list = DB::table('article')->where('title','like','%'.$keywords.'%')->orderBy('sort_order','desc')->paginate(15);
    //         }else{
    //             $list = DB::table('article')->orderBy('sort_order','desc')->paginate(15);
    //         }
    //     }
        
    //     // dump({{ $list->links() }});exit;
    //     $cate = BackstageModel::getCate('article_category',['parent_id'=>0 ]);
    //     foreach($list as $key=>$v){
    //         $typename = CommonModel::getOne('article_category',['id'=>$v->type_id]);
    //         // dump($typename->type_name);exit;
    //         $list[$key]->type_name = $typename->type_name;
    //     }
    //     return view('backstage/common/index',['cate'=>$cate,'list'=>$list]);
    // }
    // 文章
    public function article($id){
        $table = 'article';
        $data =['id'=>$id];
        $art = CommonModel::getOne($table,$data);
        // dd($art);
        return view('backstage/common/article',['art'=>$art]);
    }
    
}
